// components/count_time/count_time.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    time: {
      type: String,
      value: '00.00.00'
    }
  },

  
  /**
   * 组件的初始数据
   */
  data: {
    countTime: '00.00.00'
  },

  ready: function () {
    var that = this
    var countTime = function () {
      var count = 0
      var timer = setInterval(function () {
        var td = that.data.time.split('-').join('/')
        var timeNumber = 9, twoTime = 0
        var now = (new Date(td)) - (new Date())
        var hh = Math.floor(now / (60 * 60 * 1000))
        var mm = Math.floor(now % (60 * 60 * 1000) / (60 * 1000))
        var ss = Math.floor(now % (60 * 60 * 1000) % (60 * 1000) / 1000)
        clearInterval(_timer);
        if (now <= 0) {
          clearInterval(timer);
          that.setData({
            countTime: '00.00.00'
          })
          return;
        }
        var _timer = setInterval(function () {
          twoTime++;
          var a = (hh >= 10 ? hh : "0" + hh) + ":" + (mm >= 10 ? mm : "0" + mm) + ":" + (ss >= 10 ? ss : "0" + ss)
          that.setData({
            countTime: a
          })
          if (twoTime == 20) {
            clearInterval(_timer)
          }
        }, 50)
      }, 1000)
    }
    countTime()
  },
  methods: {}
})
